import request from '@/axios'

export interface SysUser {
  userId?: number
  userName: string
  loginName?: string
  password?: string
  passwordExpirationDate?: string
  email?: string
  phone?: string
  loginTime?: string
  loginLastTime?: string
  loginCount?: number
  loginFailCount?: number
  isLock?: number
  systemCode?: string
  createUserId?: number
  createUserName?: string
  createTime?: string
  updateUserId?: number
  updateUserName?: string
  updateTime?: string
}

export interface UserQueryParams {
  pageNum?: number
  pageSize?: number
  userName?: string
  loginName?: string
  email?: string
  phone?: string
  isLock?: number
  systemCode?: string
}

// 获取用户列表
export function getUserList(params: UserQueryParams) {
  return request.post({
    url: '/api/system/user/list',
    data: params
  })
}

// 新增用户
export function addUser(data: SysUser) {
  return request.post({
    url: '/api/system/user',
    data
  })
}

// 更新用户
export function updateUser(data: SysUser) {
  return request.put({
    url: `/api/system/user/${data.userId}`,
    data
  })
}

// 删除用户
export function deleteUser(userId: number) {
  return request.delete({
    url: `/api/system/user/${userId}`
  })
}

// 获取用户详情
export function getUserDetail(userId: number) {
  return request.get({
    url: `/api/system/user/${userId}`
  })
}

// 批量删除用户
export function batchDeleteUser(userIds: number[]) {
  return request.delete({
    url: '/api/system/user/batch',
    data: userIds
  })
}
